package com.jhxx.controller;

import com.jhxx.entity.UserIntegral;
import com.jhxx.service.UserIntegralService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * Author chengxu
 * Date  2019-12-09
 */
@RestController
@RequestMapping(value = "/userIntegral")
public class UserIntegralController {
    @Autowired
    private UserIntegralService userIntegralService;

    @RequestMapping(value = {"/list", ""}, method = RequestMethod.GET)
    public Object list() {
        List<UserIntegral> userIntegrals = userIntegralService.findAllList();
        return userIntegrals;
    }

    @RequestMapping(value = {"/get"}, method = RequestMethod.GET)
    public Object get(@RequestParam String id) {
        UserIntegral userIntegral = userIntegralService.get(id);
        return userIntegral;
    }

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public String insert(@RequestBody UserIntegral userIntegral) {
        if (userIntegralService.insert(userIntegral) > 0) {
            return "success";
        } else {
            return "failed";
        }
    }

    @RequestMapping(value = "/insertBatch", method = RequestMethod.POST)
    public String insertBatch(@RequestBody List<UserIntegral> userIntegrals) {
        if (userIntegralService.insertBatch(userIntegrals) > 0) {
            return "success";
        } else {
            return "failed";
        }
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public String update(@RequestBody UserIntegral userIntegral) {
        if (userIntegralService.update(userIntegral) > 0) {
            return "success";
        } else {
            return "failed";
        }
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public String delete(@RequestBody UserIntegral userIntegral) {
        if (userIntegralService.delete(userIntegral) > 0) {
            return "success";
        } else {
            return "failed";
        }
    }

}
